package cn.wk.servlet;

import cn.wk.entity.Score;
import cn.wk.services.ScoreServices;
import cn.wk.services.impl.ScoreServicesImpl;
import cn.wk.util.ConvertUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/ServletsubjectShow")
public class ServletsubjectShow extends HttpServlet {
    private ScoreServices ss=new ScoreServicesImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String tno=(String) request.getSession().getAttribute("no");
        String couname=request.getParameter("couname");
        int page =Integer.parseInt(request.getParameter("page"));
        int limit =Integer.parseInt(request.getParameter("limit"));
        List<Score>list=ss.getAll(tno,couname,(page-1)*limit,limit);
        int count=ss.CountSize(couname);
        String str=ConvertUtil.ConvertPageJson(list,count);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(str);
    }
}
